//////////////////////////////////////////////////////////////////////
// Effect.h
//
// SHEN Fangyang
// me@shenfy.com
//
// Copyright (C) SHEN Fangyang, 2011, All rights reserved.
//////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////
//  Brief Description
//
//	ID3D10Effect wrapper, loads shaders from .fx file
//
//////////////////////////////////////////////////////////////////////
#pragma once
#include <string>
#include <boost/unordered_map.hpp>
#include <BasisObj.h>

namespace grflib
{
    namespace engine
    {
        namespace core
        {
            struct CMaterial;

            class CEffect
                : public IResource
            {
            public:
                //effect/shader variable usage
                enum SVUsage {SVUSE_MATRIX = 0, SVUSE_VECTOR, SVUSE_SCALAR, SVUSE_SHADER_RESOURCE};				

                //inherited methods
                CEffect(void);
                virtual ~CEffect(void);

                virtual HRESULT OnCreateDevice(ID3D10Device *pd3dDevice,
                    const DXGI_SURFACE_DESC *pBufferSurfaceDesc);
                virtual void OnDestroy(void);
                virtual void Release(void) {}

                //public methods
                inline _TSTRING &FileName() {return m_filename;}
                void AddTechnique(const std::string &name);
                void AddShaderVariable(const std::string &name, SVUsage usage);
                ID3D10EffectVariable *GetShaderVariable(const std::string &name);
                ID3D10EffectTechnique *GetTechnique(const std::string &name);
                std::size_t GetVSSignature(ID3D10EffectPass *pPass);

                virtual HRESULT SetShaderVariables(boost::shared_ptr<CMaterial> &pMaterial, const std::string &strTechnique);

            protected:
                ID3D10Effect *m_pEffect;
                _TSTRING m_filename;

                //technique and shader variable descriptions
                typedef boost::unordered_map<std::string, std::pair<ID3D10EffectVariable *, SVUsage>>::iterator shader_var_iter;
                typedef boost::unordered_map<std::string, ID3D10EffectTechnique *>::iterator technique_iter;
                boost::unordered_map<std::string, std::pair<ID3D10EffectVariable *, SVUsage>> m_pShaderVars;
                boost::unordered_map<std::string, ID3D10EffectTechnique *> m_pTechniques;

                //vertex shader signatures
                boost::unordered_map<ID3D10EffectPass *, std::size_t> m_VSSignatures;
            };

        } //namespace core
    } //namespace engine
} //namespace grflib